找传奇、传世资源到传世资源站!

省份城市的三级联动

8.5玩家评分(1人评分)
下载后可评
介绍 评论 失效链接反馈

省份城市的三级联动
from clipboard
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>省份城市的三级联动</title>
</head>
<body>
<form>
<select id='province'>
<option value='-1'>请选择</option>
</select>
<select id='city'></select>
<select id='country'></select>
</form>

<script type="text/javascript">
var provinceArr = ['上海', '江苏', '河北'];
var cityArr = [
['上海市'],
['苏州市', '南京市', '扬州市'],
['哈尔滨市', '鹤岗市', '河北']
];
var countryArr = [
[
['黄浦区', '静安区', '长宁区', '浦东区']
],
[
['虎丘区', '吴中区', '相城区', '姑苏区', '吴江区'],
['玄武区', '秦淮区', '建邺区', '鼓楼区', '浦口区'],
['邗江区', '广陵区', '江都区']
],
[
['长宁区', '桥西区', '新华区', '井陉矿区'],
['海港区', '山海关区', '北戴河区', '抚宁区'],
['桥东区', '桥西区', '宣化区', '下花园区']
]
];

function createOption(obj, data) {
for (var i in data) {
var op = new Option(data[i], i);
obj.options.add(op);
}
}
var province = document.getElementById('province');
createOption(province, provinceArr);
var city = document.getElementById('city');
province.onchange = function() {
city.options.length = 0;
createOption(city, cityArr[province.value]);
if (province.value >= 0) {
city.onchange();
} else {
country.options.length = 0;
}
};
var country = document.getElementById('country');
city.onchange = function() {
country.options.length = 0;
createOption(country, countryArr[province.value][city.value]);
}
</script>
</body>
</html>

评论

发表评论必须先登陆, 您可以 登陆 或者 注册新账号 !


在线咨询: 问题反馈
客服QQ:174666394

有问题请留言,看到后及时答复